#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

class Solution
{
public:
    int findMinMoves(vector<int> &machines)
    {
        int sum = 0;
        for (int num : machines)
        {
            sum += num;
        }
        if (sum % machines.size() != 0)
            return -1; //肯定不行
        int target = sum / machines.size();
        int res = 0;
        for (int i = 0; i < machines.size() - 1; i++)
        {
            res = max(res, abs(target - machines[i]));
            res = max(res, machines[i + 1] - target);
            machines[i + 1] -= (target - machines[i]);
        }
        return res;
    }
};